package com.shitou.web;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.shitou.pojo.Comment;
import com.shitou.pojo.Document;
import com.shitou.pojo.Issues;
import com.shitou.pojo.User;
import com.shitou.service.CommentService;

@Results({@Result(name=BaseAction.ISSUES,location="issues.jspx",params={"id","${issues.id}"},type="redirectAction"),
	@Result(name=BaseAction.DOCUMENT,location="document.jspx",params={"id","${document.id}"},type="redirectAction")})
public class CommentAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	@Resource
	private CommentService commentService;
	private Comment comment;
	private Document document;
	private Issues issues;
	
	@Override
	public String del() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String save() throws Exception {

		return SUCCESS;
	}
	
	public String issuesSave() throws Exception {
		comment.setIssues(issues);
		comment.setUser((User)getSessionAttribute("user"));
		commentService.save(comment);
		return ISSUES;
	}
	
	public String documentSave() throws Exception {
		comment.setDocument(document);
		comment.setUser((User)getSessionAttribute("user"));
		commentService.save(comment);
		return DOCUMENT;
	}

	//getter and setter
	public Comment getComment() {
		return comment;
	}

	public void setComment(Comment comment) {
		this.comment = comment;
	}

	public Issues getIssues() {
		return issues;
	}

	public void setIssues(Issues issues) {
		this.issues = issues;
	}

	public Document getDocument() {
		return document;
	}

	public void setDocument(Document document) {
		this.document = document;
	}

}
